package cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.dal.dataobject.order;

import cn.iocoder.yudao.module.system.controller.admin.mini.group.order.dal.dataobject.grouporder.GroupOrderDO;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo.JslUserAddress;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo.OrderGood;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo.OrderLogistic;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 小程序-订单 DO
 *
 * @author 芋道源码
 */
@TableName(value = "qd_order",autoResultMap = true)
@KeySequence("qd_order_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@AllArgsConstructor
public class OrderDO extends BaseDO {

    /**
     * id主键
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    /**
     * 订单号
     */
    private String orderCode;
    /**
     * 订单状态  1: '代付款', 2:'待发货' ,3: '待收货' ,4: '已完成' ,5:'退款售后'
     */
    private Integer orderStatus;
    /**
     * 订单退货前状态  1: '代付款', 2:'待发货' ,3: '待收货' ,4: '已完成' ,5:'退款售后'
     */
    private Integer backStatus;
    /**
     * 收货人地址信息
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    @NotNull
    private JslUserAddress address;
    /**
     * 物流信息
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private OrderLogistic logistic;
    /**
     * 商品信息
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    @Valid
    private List<OrderGood> goods;
    /**
     * 支付状态1已支付2未支付
     */
    private Integer payStatus;
    /**
     * 支付时间
     */
    private LocalDateTime payTime;
    /**
     * 最新发货时间
     */
    private LocalDateTime logisticTime;
    /**
     * 收货确认时间
     */
    private LocalDateTime confirmTime;
    /**
     * 下单时间
     */
    private LocalDateTime addTime;
    /**
     * 订单原价
     */
    private BigDecimal totalAmount;
    /**
     * 商品总价
     */
    private BigDecimal goodsAmount;
    /**
     * 抵扣金额
     */
    private BigDecimal deduction;
    /**
     * 付款金额
     */
    private BigDecimal payPrice;
    /**
     * 运费
     */
    private BigDecimal freightPrice;
    //用户手机号
    @TableField(exist = false)
    private String phone;
    //是否是vip支付 0否1是
    private Integer isVip;

    //推荐人名称
    @TableField(exist = false)
    private String shopName;
    //用户名称
    @TableField(exist = false)
    private String nickName;
    //会员编号
    @TableField(exist = false)
    private String vipId;
    /**
     * paypal编号
     */
    private String paypalCode;
    /**
     * 余额抵扣金额
     */
    private BigDecimal balancePrice;
    /**
     * 余额抵扣id
     */
    private Integer balanceId;
    /**
     * 取货码
     */
    private String pickUpCode;
    /**
     * 取货时间
     */
    private LocalDateTime qhTime;

    public OrderDO() {
    }

    //拼团订单转订单
    public OrderDO(GroupOrderDO vo) {
        this.orderCode = vo.getOrderCode();
        this.orderStatus = 2;
        this.address = vo.getAddress();
        List<OrderGood> goods=new ArrayList<>();
        goods.add(vo.getGoods());
        this.goods = goods;
        this.payStatus = 1;
        this.payTime = vo.getPayTime();
        this.addTime = vo.getAddTime();
        this.totalAmount = vo.getTotalAmount();
        this.goodsAmount = vo.getGoodsAmount();
        this.deduction = vo.getDeduction();
        this.payPrice = vo.getPayPrice();
        this.freightPrice = vo.getFreightPrice();
        this.isVip = vo.getIsVip();
        this.paypalCode=vo.getPaypalCode();
        this.balancePrice=vo.getBalancePrice();
        this.balanceId=vo.getBalanceId();
    }
}
